package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.logic.activity.zhenhuan.ZhenHuanFirstProcessConfig;
import com.yanqu.road.logic.activity.zhenhuan.ZhenHuanSecondProcessConfig;
import com.yanqu.road.server.manger.activity.zhenhuan.ZhenHuanConfigMgr;

import java.util.ArrayList;
import java.util.List;

public class ZhenHuanRecycleStrategy extends AbstractItemRecycleStrategy {
    @Override
    public void markNeedRecycleItem() {
        ZhenHuanFirstProcessConfig firstProcessConfig = ZhenHuanConfigMgr.getFirstProcessConfig();
        if (firstProcessConfig != null) {
            int powerGoodsId = firstProcessConfig.getPowerGoodsId();
            long recycleTime = firstProcessConfig.getActivityInfo().getEndTime() * 1000L + 300 * 1000;//领奖期回收

            List<String> paramList = new ArrayList<>();
            paramList.add(String.valueOf(powerGoodsId));
            paramList.add(String.valueOf(firstProcessConfig.getExchangeGoodsId()));
            paramList.add("1");
            paramList.add(firstProcessConfig.getActivityInfo().getActivityName());

            ActivityItemRecycleMgr.addRecycleItemData(powerGoodsId, firstProcessConfig.getActivityInfo().getType(), 1, recycleTime, paramList);
        }

        ZhenHuanSecondProcessConfig secondProcessConfig = ZhenHuanConfigMgr.getSecondProcessConfig();
        if (secondProcessConfig != null) {
            int powerGoodsId = secondProcessConfig.getPowerGoodsId();
            long recycleTime = secondProcessConfig.getActivityInfo().getEndTime() * 1000L + 300 * 1000;//领奖期回收

            List<String> paramList = new ArrayList<>();
            paramList.add(String.valueOf(powerGoodsId));
            paramList.add(String.valueOf(secondProcessConfig.getExchangeItemId()));
            paramList.add("1");
            paramList.add(secondProcessConfig.getActivityInfo().getActivityName());

            ActivityItemRecycleMgr.addRecycleItemData(powerGoodsId, secondProcessConfig.getActivityInfo().getType(), 1, recycleTime, paramList);
        }
    }

    @Override
    public boolean isActivityRunning() {
        return false;
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.ZhenHuan.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        int recycleType = data.getRecycleType();
        if (recycleType == 1) {
            item2Score(userId, data);
        } else if (recycleType == 2) {
            UserBagItem item = getUserBagItem(userId, data.getItemId());
            if (item != null && item.getNum() > 0) {
                removeItem(item);
            }
        }
    }
}
